package com.fancyy.scm.activity;

import android.app.Activity;
import android.databinding.ObservableField;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.fancyy.scm.BRConstant;
import com.fancyy.scm.R;
import com.fancyy.scm.base.BaseActivity;
import com.fancyy.scm.base.annotation.Layout;
import com.fancyy.scm.base.annotation.Translucent;
import com.fancyy.scm.base.http.BRDataListener;
import com.fancyy.scm.base.http.BRDataTransport;

@Layout(R.layout.zuihou)
@Translucent
public class ChangePasswordActivity extends BaseActivity {
    public ObservableField<String> oldPwd = new ObservableField<>();
    public ObservableField<String> newPwd = new ObservableField<>();

    public void onSaveButtonClick(View view) {
        if (TextUtils.isEmpty(oldPwd.get())) {
            showToast("Old password can't be empty");
            return;
        }
        if (TextUtils.isEmpty(oldPwd.get())) {
            showToast("New password can't be empty");
            return;
        }
        BRDataTransport.create(BRConstant.CHANGE_PWD)
                .addParam("UserAccount", getBRApplication().getUserInfo().userAccount)
                .addParam("OldPassword", oldPwd.get())
                .addParam("NewPassword", newPwd.get())
                .addParam("ConfirmPassword", newPwd.get())
                .addParam("OperateUserName", getBRApplication().getUserInfo().name)
                .addParam("OperateUserAccount", getBRApplication().getUserInfo().userAccount)
                .addProgressing(this, "Progressing...")
                .execute(new BRDataListener() {
                    @Override
                    public void onSuccess(Object data) {
                        showToast("Change success!");
                        finish();
                    }
                });
    }
}
